package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.SecurityUtils;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.framework.interceptor.MyMetaObjectHandler;
import com.zzyl.nursing.dto.NursingTaskDto;
import com.zzyl.nursing.vo.NursingTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 任务安排Controller
 * 
 * @author cyc
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "任务安排相关接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;




    /**
     * 任务改期
     */
    @PutMapping("/updateTime")
    public AjaxResult taskRescheduling(@ApiParam(value = "任务改期")@RequestBody NursingTaskDto nursingTaskDto){
        return success(nursingTaskService.taskRescheduling(nursingTaskDto));
    }

    @PutMapping("/do")
    public AjaxResult doTask(@RequestBody NursingTaskDto dto){
        nursingTaskService.doTask(dto);
        return success();
    }

    /**
     *  取消护理任务
     * @param dto
     * @return
     */
    @PutMapping("/cancel")
    public AjaxResult cancelTask(@RequestBody NursingTaskDto dto){

        nursingTaskService.cancelTask(dto);
        return success();
    }


    /**
     * 查看护理任务详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult queryTaskById(@PathVariable Integer id){
        NursingTaskVo vo=nursingTaskService.queryTaskById(id);
        return success(vo);
    }


    /**
     * 查询任务安排列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取任务安排列表")
    public TableDataInfo<List<NursingTask>> list(NursingTask nursingTask)
    {
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        return getDataTable(list);
    }

    /**
     * 导出任务安排列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:export')")
    @Log(title = "任务安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出任务安排列表")
    public void export(HttpServletResponse response, NursingTask nursingTask)
    {
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTask);
        ExcelUtil<NursingTask> util = new ExcelUtil<NursingTask>(NursingTask.class);
        util.exportExcel(response, list, "任务安排数据");
    }

//    /**
//     * 获取任务安排详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:query')")
//    @GetMapping(value = "/{id}")
//    @ApiOperation("获取任务安排详细信息")
//    public R<NursingTask> getInfo(@ApiParam(value = "任务安排ID", required = true)
//            @PathVariable("id") Long id)
//    {
//        return R.ok(nursingTaskService.selectNursingTaskById(id));
//    }

    /**
     * 新增任务安排
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:add')")
    @Log(title = "任务安排", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增任务安排")
    public AjaxResult add(@ApiParam(value = "任务安排实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.insertNursingTask(nursingTask));
    }

    /**
     * 修改任务安排
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:edit')")
    @Log(title = "任务安排", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改任务安排")
    public AjaxResult edit(@ApiParam(value = "任务安排实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.updateNursingTask(nursingTask));
    }

    /**
     * 删除任务安排
     */
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:remove')")
    @Log(title = "任务安排", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除任务安排")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(nursingTaskService.deleteNursingTaskByIds(ids));
    }
}
